home *** CD-ROM | disk | FTP | other *** search
- /*
- * GetAttribute.c
- */
-
- #include "SimpleDrag.h"
-
- #define kGetAttrBufferSize (4096) /* Working data buffer */
-
- static pascal Boolean myForEachLookupRecordID (long clientData, const RecordID *recordID);
- static pascal Boolean myForEachAttrValue (long clientData, const Attribute *attribute);
- static pascal Boolean myForEachAttrTypeLookup (long clientData,
- const AttributeType *attrType, AccessMask myAttrAccMask);
-
-
-
-
- /*********************************************************************************
- * OpenPersonalCatalog
- * If the current selection is an alias, open the personal address catalog that is
- * related to that alias. The personal catalog is opened for reading. Note:
- * this function returns kOCEMiscError if the rli is *not* an alias. This
- * is not really an error. Other error returns indicate a failed attempt to
- * open the catalog.
- *********************************************************************************/
- OSErr
- OpenPersonalCatalog(
- PackedRLIPtr rli,
- short *dsRefNumPtr
- )
- {
- OSErr status;
- AliasPtr aliasPtr;
- AliasHandle aliasHandle;
- Boolean wasChanged;
- FSSpec theFSSpec;
- DirParamBlock dirParamBlock;
- #define OPEN (dirParamBlock.openPersonalDirectoryPB)
-
- aliasHandle = NULL;
- *dsRefNumPtr = 0;
- status = noErr;
- if (OCEValidPackedRLI(rli) == false
- || (aliasPtr = OCEExtractAlias(rli)) == NULL)
- status = kOCEMiscError; /* Not an alias */
-
- if (status == noErr)
- {
- status = PtrToHand((Ptr) aliasPtr,
- (Handle *) &aliasHandle,
- aliasPtr->aliasSize);
- }
-
- if (status == noErr)
- status = ResolveAlias(NULL, aliasHandle, &theFSSpec, &wasChanged);
-
- if (aliasHandle != NULL)
- DisposeHandle((Handle) aliasHandle);
-
- if (status == noErr)
- {
- OPEN.fsSpec = &theFSSpec;
- OPEN.accessRequested = fsRdPerm;
- status = DirOpenPersonalDirectory(&dirParamBlock);
- if (status == noErr)
- *dsRefNumPtr = OPEN.dsRefNum;
- }
-
- return (status);
- #undef OPEN
- }
-
-
-
-
-
- /*****************************************************************************
- * GetAttributeFromRID
- * Given a record id, this routine performs a DirLookUpGet/DirLookUpParse
- * combination to retrieve the attributes of the given type from the record.
- *
- *****************************************************************************/
-
- OSErr GetAttributeFromRID ( RecordIDPtr rid,
- short dsRefNum,
- const AttributeTypePtr attributeType,
- AttributePtr attributePtr,
- AuthIdentity identity)
- {
- OSErr err;
- RecordIDPtr recordList[1];
- AttributeTypePtr attTypeList[1];
- DirParamBlock dirParamBlock;
- Ptr buffer;
- #define GET (dirParamBlock.lookupGetPB)
- #define PARSE (dirParamBlock.lookupParsePB)
-
-
- recordList[0] = rid;
- attTypeList[0] = attributeType;
-
- buffer = NewPtr(kGetAttrBufferSize);
- if (buffer == NULL)
- err = MemError();
- else
- {
- GET.serverHint.aNet = 0;
- GET.serverHint.aNode = 0;
- GET.serverHint.aSocket = 0;
- GET.dsRefNum = dsRefNum;
- GET.identity = identity;
- GET.clientData = 0L;
- GET.aRecordList = &recordList;
- GET.attrTypeList = &attTypeList;
- GET.recordIDCount = 1;
- GET.attrTypeCount = 1;
- GET.includeStartingPoint = true;
- GET.getBuffer = buffer;
- GET.getBufferSize = kGetAttrBufferSize;
- GET.startingRecordIndex = 1;
- GET.startingAttrTypeIndex = 1;
- GET.startingAttribute.cid.source = 0L;
- GET.startingAttribute.cid.seq = 0L;
- err = DirLookupGet (&dirParamBlock, false);
-
- if (err == noErr || err == kOCEMoreData)
- {
-
- PARSE.clientData = (long) attributePtr;
- PARSE.eachRecordID = myForEachLookupRecordID;
- PARSE.eachAttrType = myForEachAttrTypeLookup;
- PARSE.eachAttrValue = myForEachAttrValue;
-
- err = DirLookupParse (&dirParamBlock, false);
- }
-
- DisposePtr (buffer);
- }
-
- return (err);
- #undef GET
- #undef PARSE
-
- }
-
- static pascal Boolean myForEachLookupRecordID ( long clientData,
- const RecordID *recordID)
- {
- #pragma unused (clientData,recordID)
-
- return (false);
- }
-
- static pascal Boolean myForEachAttrTypeLookup ( long clientData,
- const AttributeType *attrType,
- AccessMask myAttrAccMask)
- {
- #pragma unused (clientData,attrType,myAttrAccMask)
-
- return (false);
- }
-
- static pascal Boolean myForEachAttrValue ( long clientData,
- const Attribute *attribute)
- {
- AttributePtr theAttribute;
-
- theAttribute = (AttributePtr) clientData;
- memcpy (theAttribute, (Ptr) attribute, sizeof (Attribute));
-
- if (((*theAttribute).value.bytes = NewPtr ((*attribute).value.dataLength)) != NULL)
- memcpy ((*theAttribute).value.bytes, (*attribute).value.bytes,
- (*attribute).value.dataLength);
- else
- {
- /* couldn't allocate memory for the attribute value, so we punt
- and zero out the attribute value fields */
- (*theAttribute).value.dataLength = 0; /* 0 length */
- (*theAttribute).value.bytes = NULL; /* null ptr to attr. value data */
- }
-
- return (true);
- }